﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace Sino.CapacityCloud.Repositories.Models
{

    public class TransportLinkageDetail
    {

        public string StartingPlaceCode { get; set; }

        [NotMapped]
        public Point StartingPlaceLocation { get; set; }

        public string StartingPlaceName { get; set; }

        public string DestinationPlaceCode { get; set; }

        [NotMapped]
        public Point DestinationPlaceLocation { get; set; }

        public string DestinationPlaceName { get; set; }

        public string Remarks { get; set; }

#if !DNXCORE50
        [System.ComponentModel.Browsable(false)]
#endif
        [Column("StartingPlaceLocation_Latitude")]
        public double StartingPlaceLocationLatitude
        {
            get
            {
                return StartingPlaceLocation.Latitude;
            }
            set
            {
                var structValue = StartingPlaceLocation;
                structValue.Latitude = value;
                StartingPlaceLocation = structValue;
            }
        }

#if !DNXCORE50
        [System.ComponentModel.Browsable(false)]
#endif
        [Column("StartingPlaceLocation_Longitude")]
        public double StartingPlaceLocationLongitude
        {
            get
            {
                return StartingPlaceLocation.Longitude;
            }
            set
            {
                var structValue = StartingPlaceLocation;
                structValue.Longitude = value;
                StartingPlaceLocation = structValue;
            }
        }

#if !DNXCORE50
        [System.ComponentModel.Browsable(false)]
#endif
        [Column("DestinationLocation_Latitude")]
        public double DestinationLocationnLatitude
        {
            get
            {
                return DestinationPlaceLocation.Latitude;
            }
            set
            {
                var structValue = DestinationPlaceLocation;
                structValue.Latitude = value;
                DestinationPlaceLocation = structValue;
            }
        }

#if !DNXCORE50
        [System.ComponentModel.Browsable(false)]
#endif
        [Column("DestinationLocation_Longitude")]
        public double DestinationLocationLongitude
        {
            get
            {
                return DestinationPlaceLocation.Longitude;
            }
            set
            {
                var structValue = DestinationPlaceLocation;
                structValue.Longitude = value;
                DestinationPlaceLocation = structValue;
            }
        }

        public TransportLinkageDetail()
        {
            this.StartingPlaceLocation = new Point();
            this.DestinationPlaceLocation = new Point();
        }

        public override bool Equals(object obj)
        {
            var r = obj as TransportLinkageDetail;
            if (r != null)
            {
                return this.StartingPlaceCode == r.StartingPlaceCode &&
                    this.DestinationPlaceCode == r.DestinationPlaceCode &&
                    this.StartingPlaceLocation == r.StartingPlaceLocation &&
                    this.DestinationPlaceLocation == r.DestinationPlaceLocation;
            }
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

    }

}